import store from './index';
import * as types from './mutation-types';

// im 相关

export const initIMService = () => {
	return store.commit(types.INIT_IM_SERVICE);
};

export const disconnectIMService = () => {
	return store.commit(types.DISCONNECT_IM_SERVICE);
};
export const reconnctionIMService = (force = false) => {
	return store.commit(types.RECONNECTION_IM_SERVICE, force);
};

//用户相关

export const updateUserToken = (token) => {
	return store.commit(types.UPDATE_USER_TOKEN, token);
};


export const updateUserInfo = (info) => {
	return store.commit(types.UPDATE_USER_INFO, info);
};
export const exitAndClear = () => {
	return store.commit(types.EXIT_AND_CLEAR);
};

export const updateRefereeCode = (refereeCode = '') => {
	return store.commit(types.UPDATE_REFEREE_CODE, refereeCode);
};

export const updateMemberSetting = (setting) => {
	return store.commit(types.UPDATE_MEMBER_SETTING, setting)
}

export const updateMemberMatchmaker = () => {
	return store.commit(types.UPDATE_MEMBER_MATCHMAKER)
}


//消息相关
export const getSingleSessionList = (callback = null) => {
	return store.commit(types.GET_SINGLE_SESSION_LIST, callback)
}

export const getGroupSessionList = (page = { num: 1, size: 200 }) => {
	return store.dispatch(types.GET_GROUP_SESSION_LIST, page)
}

export const showSingleSessionListSwipeAction = (index = -1) => {
	return store.commit(types.SHOW_SINGLE_SESSION_LIST_SWIPE_ACTION, index)
}

export const getNoticeList = (callback = null) => {
	return store.commit(types.GET_NOTICE_LIST, callback)
}


export const setSingleSessionRead = (sessionIds) => {
	return store.commit(types.SET_SINGLE_SESSION_READ, String(sessionIds))
}

export const deleteSingleSessionItem = (sessionIds) => {
	return store.commit(types.DELETE_SINGLE_SESSION_ITEM, String(sessionIds))
}

export const updateUnreadCount = (data = {}) => {
	return store.commit(types.UPDATE_UNREAD_COUNT, data);
}

export const setGroupSessionRead = (groupIds) => {
	return store.commit(types.SET_GROUP_SESSION_READ, String(groupIds))
}

export const setNoticeRead = (keys) => {
	return store.commit(types.SET_NOTICE_READ, String(keys))
}

//设备相关

export const updateNetworkType = (networkType) => {
	return store.commit(types.UPDATE_NETWORK_TYPE, networkType);
};
export const saveNewVersion = (data) => {
	console.log(data)
	return store.commit(types.SAVE_NEW_VERSION, data);
};

export const updataDeviceModel = (model) => {
	return store.commit(types.UPDATE_DEVICE_MODEL, model);
};
export const updateDevicePermission = (item = {}) => {
	if (!item.key) {
		return false;
	}
	return store.commit(types.UPDATE_DEVICE_PERMISSION, item);
};

export const closeNoticePremissionTip = () => {
	return store.commit(types.CLOSE_NOTICE_PREMISSION_TIP);
};

export const storageCache = (item = {}) => {
	console.log(item)
	if (!item.key) {
		return false;
	}
	return store.commit(types.STORAGE_CACHE, item);
};

export const clearStorageCache = () => {
	return store.commit(types.CLEAR_STORAGE_CACHE);
};



export const initCacheSize = () => {
	return store.commit(types.INIT_CACHE_SIZE);
};
